package com.whfc.ms.api.base.controller;

import com.whfc.base.dto.AppWeatherDTO;
import com.whfc.base.dto.AppWeatherLogDTO;
import com.whfc.base.dto.AppWeatherScheduleDTO;
import com.whfc.base.dto.WeatherDTO;
import com.whfc.common.base.BaseController;
import com.whfc.common.result.ListData;
import com.whfc.common.result.R;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.base.service.AppWeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/ms/api")
public class AppWeatherController extends BaseController {

    @Autowired
    private AppWeatherService appWeatherService;

    /**
     * 获取项目的天气预报
     *
     * @param user
     * @param deptId
     * @return
     */
    @GetMapping(value = {"weather/current", "/getWeather"})
    public Result getWeather(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @RequestParam("deptId") Integer deptId) {
        logger.info("获取项目的天气预报,loginer:{},deptId:{}", user.getUsername(), deptId);
        //获取天气预报
        WeatherDTO data = appWeatherService.getWeather(deptId);
        return ResultUtil.success(data);
    }

    /**
     * 获取历史天气预报(按月,每天3个时间段)
     *
     * @param user
     * @param deptId
     * @return
     */
    @GetMapping(value = {"weather/history", "/weatherHistory"})
    public Result getMonthWeatherHistory(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                         @RequestParam("deptId") Integer deptId,
                                         @DateTimeFormat(pattern = "yyyy-MM") @RequestParam("time") Date time) {
        logger.info("获取历史天气预报(按月,每天3个时间段),loginer:{},deptId:{},time：{}", user.getUsername(), deptId, time);
        //获取天气预报
        ListData<AppWeatherLogDTO> data = appWeatherService.getMonthWeatherHistory(deptId, time);
        return ResultUtil.success(data);
    }


    /**
     * 2.0 获取天气预报以及日程
     *
     * @param user
     * @param deptId
     * @return
     */
    @GetMapping(value = {"weather/schedule", "/weatherSchedule"})
    public R<List<AppWeatherDTO>> getWeatherAndSchedule(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                         @RequestParam("deptId") Integer deptId,
                                         @DateTimeFormat(pattern = "yyyy-MM") @RequestParam("time") Date time) {
        logger.info("获取历史天气预报(按月,每天3个时间段),loginer:{},deptId:{},time：{}", user.getUsername(), deptId, time);
        //获取天气预报
        List<AppWeatherScheduleDTO> data = appWeatherService.getMonthWeatherSchedule(deptId, time,user.getId());
        return R.success(data);
    }


}
